﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace The_LarX
{
    public class VSR_ObjectNeeded : VSRBase
    {
        public RectangleOwner ObjectRectangle;

        public VSR_ObjectNeeded()
        {
        }

        public override void Start(VisualScript_Node Node, VisualScriptEditor editor)
        {
            IVisualScriptNode_NeedObject node = Node as IVisualScriptNode_NeedObject;
            this.ObjectRectangle = new RectangleOwner(this, new Rectangle(), node.Objects, ExpectedNode.Object);
            editor.Rectangles.Add(ObjectRectangle);

            Size = new Vector2(150, 90);

            base.Start(Node, editor);
        }

        protected int ObjRectSize = 26;
        public override void UpdateSizeAndPos()
        {
            base.UpdateSizeAndPos();

            // TOP RECTANGLE FORMULE
            /*ObjectRectangle.Rectangle.X = (int)Position.X + (((int)Size.X / 2) - ObjRectSize / 2);
            ObjectRectangle.Rectangle.Y = (int)Position.Y;
            ObjectRectangle.Rectangle.Width = ObjRectSize;
            ObjectRectangle.Rectangle.Height = ObjRectSize;*/

            ObjectRectangle.Rectangle.X = (int)(Position.X + ((Size.X / 2) - ObjRectSize / 2));
            ObjectRectangle.Rectangle.Y = (int)(Position.Y + Size.Y - ObjRectSize);
            ObjectRectangle.Rectangle.Width = ObjRectSize;
            ObjectRectangle.Rectangle.Height = ObjRectSize;
        }

        public override void Draw()
        {          
            IVisualScriptNode_NeedObject node = Node as IVisualScriptNode_NeedObject;
            for (int i = 0; i < node.Objects.Count; i++)
            {
                Rectangle first = ObjectRectangle.Rectangle;
                Rectangle second = node.Objects[i].Representation.RightRectangle.Rectangle;
                Engine.RenderManager.Draw2DLine(new Vector2(first.X + (first.Width / 2),
                    first.Y + (first.Height / 2)),
                    new Vector2(second.X + (second.Width / 2),
                        second.Y + (second.Height / 2))
                        , Camera, Color.Aqua, 5);
            }

            base.Draw();
            ObjectRectangle.Draw(Camera);
        }
    }
}
